package org.global.basic.specification;

import lombok.Getter;
import lombok.Setter;
import org.global.GEntity;
import org.springframework.data.jpa.domain.Specification;
import javax.persistence.criteria.*;
import java.io.Serializable;

@Getter
@Setter
public class SpecificationById<T extends GEntity<ID>, ID extends Serializable> implements Specification<T> {

    private ID id;

    @Override
    public Predicate toPredicate(Root<T> root,
                                 CriteriaQuery<?> query,
                                 CriteriaBuilder cb) {
        Predicate pId = cb.equal(root.get("id").as(String.class), id);
        Predicate pDel = cb.equal(root.get("del").as(Boolean.class), false);
        return cb.and(pId, pDel);
    }
}
